{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "98ff2188c1c241e2",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2024-05-16T06:43:49.304431Z"
    },
    "collapsed": false,
    "is_executing": true,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 26\u001b[0m\n\u001b[0;32m     23\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m iterations\n\u001b[0;32m     25\u001b[0m \u001b[38;5;66;03m# 调用函数并打印结果\u001b[39;00m\n\u001b[1;32m---> 26\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m主体B超过主体A所需的循环次数是：\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[43mcalculate_progression_iterations\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m)\n",
      "Cell \u001b[1;32mIn[1], line 6\u001b[0m, in \u001b[0;36mcalculate_progression_iterations\u001b[1;34m()\u001b[0m\n\u001b[0;32m      3\u001b[0m subject_B \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m  \u001b[38;5;66;03m# 主体B的起始值\u001b[39;00m\n\u001b[0;32m      4\u001b[0m iterations \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m  \u001b[38;5;66;03m# 循环次数\u001b[39;00m\n\u001b[1;32m----> 6\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m      7\u001b[0m     iterations \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m  \u001b[38;5;66;03m# 每次循环增加一次计数\u001b[39;00m\n\u001b[0;32m      9\u001b[0m     \u001b[38;5;66;03m# 主体A每天进步0.1\u001b[39;00m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "\n",
    "def calculate_progression_iterations():\n",
    "    subject_A = 1  # 主体A的起始值\n",
    "    subject_B = 1  # 主体B的起始值\n",
    "    iterations = 0  # 循环次数\n",
    "\n",
    "    while True:\n",
    "        iterations += 1  # 每次循环增加一次计数\n",
    "\n",
    "        # 主体A每天进步0.1\n",
    "        subject_A += 0.1\n",
    "\n",
    "        # 主体B工作日进步0.1，休息日倒退0.1\n",
    "        # 假设每5天中有4个工作日和1个休息日\n",
    "        if iterations % 5 < 4:\n",
    "            subject_B += 0.1\n",
    "        else:\n",
    "            subject_B -= 0.1\n",
    "\n",
    "        # 检查主体B是否超过主体A\n",
    "        if subject_B > subject_A:\n",
    "            break\n",
    "\n",
    "    return iterations\n",
    "\n",
    "# 调用函数并打印结果\n",
    "print(\"主体B超过主体A所需的循环次数是：\", calculate_progression_iterations())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7eaa4a01-652e-4be9-8dbb-415b5d67ef65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n"
     ]
    }
   ],
   "source": [
    "def square(number):\n",
    "    return number ** 2\n",
    "\n",
    "\n",
    "def is_even(number):     #判断是否为一个偶数\n",
    "    if number % 2 == 0:\n",
    "        return True\n",
    "    else:\n",
    "        return False\n",
    "num = 4\n",
    "if is_even(num):\n",
    "    result = square(num)\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e137164-2890-4172-bb00-cebb95fbb57d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def print_local():\n",
    "    y = 5\n",
    "    print(y)\n",
    "\n",
    "\n",
    "print_local()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c69bbeb-f101-4d5d-b083-0fecc857adcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 10\n",
    "\n",
    "\n",
    "def modify_global():\n",
    "    global x\n",
    "    x = 20\n",
    "\n",
    "\n",
    "print(x)\n",
    "modify_global()\n",
    "print(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
